﻿
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections.Generic;
using System.Reflection;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Web.UI;

using Swaf;
using Swaf.BizObj;
using Swaf.Container;
using Swaf.Security;
using Swaf.Gui;
using Swaf.Gui.AspNet2;


namespace Syrinx.Gui.AspNet.Ajax
{
	public class ComplexTreeBizObjListDisplay : ComplexBizObjListDisplay
	{
		protected int m_lastDepth = -1;
		protected int m_preOpenLevel = 0;

		public ComplexTreeBizObjListDisplay()
			:base()
		{
		}

		public ComplexTreeBizObjListDisplay(ActiveWidget widget)
			:base(widget)
		{
		}

		public int PreOpenLevel { get { return m_preOpenLevel; } }

		public string beforeBlock()
		{
			int curDepth = Depth;
			if(curDepth > m_lastDepth)
				if(curDepth <= 0)
					return "<ul class='OT'><li>";
				else
					return "<ul class='CT'><li>";

			return "<li>";
		}

		public string afterBlock()
		{
			StringBuilder buff = new StringBuilder(100);
			if (!HasChildren)
				buff.Append("</li>");
			int curDepth = Depth;
			int nextDepth = -1;
			if(!IsLast)
				nextDepth = (int)((IBizObj)m_bizObjCursor.Source[Index + 1]).get("depth");

			for (int p = curDepth; p > nextDepth; p--)
				buff.Append("</ul></li>");
			if (nextDepth == -1)
				buff.Length = buff.Length - 5;

			m_lastDepth = curDepth;
			return buff.ToString();
		}
	}
}
